package com.zxl.admin.controller.information;


import com.github.pagehelper.PageInfo;
import com.zxl.admin.service.InformationService;
import com.zxl.common.Page;
import com.zxl.common.Result;
import com.zxl.common.model.bo.information.InformationGroupSaveBo;
import com.zxl.common.model.bo.information.InformationSaveBo;
import com.zxl.common.model.pojo.SysInformation;
import com.zxl.common.model.pojo.SysInformationGroup;
import com.zxl.common.model.query.information.InformationGroupQuery;
import com.zxl.common.model.query.information.InformationQuery;
import com.zxl.common.model.vo.information.InformationVo;
import com.zxl.common.service.SysInformationGroupService;
import com.zxl.common.service.SysInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 *
 * @author zxw
 * @since 2023-04-24
 */
@Api(tags = "新闻管理")
@RestController
@RequestMapping("/admin/information")
public class InformationController {
    @Resource
    private InformationService informationService;

    @ApiOperation("新增新闻")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid InformationSaveBo bo) {
        informationService.add(bo);
        return Result.success();
    }

    @ApiOperation("修改新闻")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid InformationSaveBo bo) {
        informationService.update(bo);
        return Result.success();
    }

    @ApiOperation("获取新闻列表")
    @GetMapping("/list")
    public Result<Page<InformationVo>> getGoodsList(InformationQuery informationQuery) {
        List<InformationVo> list = informationService.getList(informationQuery);
        Page<InformationVo> page = Page.pageInfoConvert(new PageInfo(list));
        return new Result(page);
    }

    @PostMapping("/delete")
    @ApiOperation("删除")
    public Result delete(@RequestParam @ApiParam(value = "id") Integer id) {
        informationService.delete(id);
        return Result.success("删除成功");
    }

}
